<?php

namespace App\Modules\Api\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\Api\MsgService;
use Illuminate\Support\Facades\Log;
use App\Modules\Api\Http\Controllers\BaseController;

class MsgController extends BaseController
{

    /**
     * 消息列表接口
     * @param Request $request
     * @method msgList
     * @author chengzhigang<1256699215@qq.com>
     */
    public function msgList(Request $request){
        $token = $request -> input('token');
        if (empty($token)) {
            return apiResponse('请登录应用');
        }
        $MsgService = new MsgService();
        $result = $MsgService->msgList($token);
        return apiResponse($result['msg'],$result['status'],$result['data']);
    }

    /**
     * 获取未读消息总数
     * @param Request $request
     * @method getUnReadCount
     * @author chengzhigang<1256699215@qq.com>
     */
    public function getUnReadCount(Request $request){
        $token = $request -> input('token');
        if (empty($token)) {
            return apiResponse('请登录应用');
        }
        $MsgService = new MsgService();
        $result = $MsgService->getUnReadCount($token);
        return apiResponse($result['msg'],$result['status'],$result['data']);
    }

    /**
     * 获取消息类型列表
     * @param Request $request
     * @method msgInfoList
     * @author chengzhigang<1256699215@qq.com>
     */
    public function msgInfoList(Request $request){
        $token = $request -> input('token');
        $type = $request -> input('type',1);
        $page = $request -> input('page',1);
        $per_page = $request -> input('per_page',15);
        if (empty($token)) {
            return apiResponse('请登录应用');
        }
        if(empty($page)||!is_numeric($page)){
            return apiResponse('当前页数格式不正确');
        }
        if(empty($per_page)||!is_numeric($per_page)){
            return apiResponse('每页数量格式不正确');
        }
        $MsgService = new MsgService();
        $result = $MsgService->msgInfoList($token,$type,$page,$per_page);
        return apiResponse($result['msg'],$result['status'],$result['data']);
    }

    /**
     * 获取消息详情
     * @param Request $request
     * @method msgDetail
     * @author chengzhigang<1256699215@qq.com>
     */
    public function msgDetail(Request $request){
        $token = $request -> input('token');
        $id = $request -> input('id');
        if (empty($token)) {
            return apiResponse('请登录应用');
        }
        if(empty($id)||!is_numeric($id)){
            return apiResponse('消息id格式不正确');
        }
        $MsgService = new MsgService();
        $result = $MsgService->msgDetail($token,$id);
        return apiResponse($result['msg'],$result['status'],$result['data']);
    }

}
